<?php
  #--------------------------------------------------
  # ALL INCLUDES + STANDARD-VALUES
  #--------------------------------------------------
  include_once("../include/author.php5");
  include_once("../include/config.inc");
  include_once("../include/template.inc");
  include_once("../include/class.db.php5");
  include_once("../include/class.tools.php5");
  include_once("../include/class.time.php5");
  $svo = new db("svoptik");
  $tools = new tool();
  $time = new TimeUtil();
  include_once("../include/global_fix_intern.inc");
  #--------------------------------------------------
  # CREATE TEMPLATE
  #--------------------------------------------------
  $t = new Template("templates", "keep");
  $t->set_file(array("page" => "svoptik.tpl",
                     "navi" => "navi.tpl",
                     "news" => "news.tpl"));
  #--------------------------------------------------


  #--------------------------------------------------
  # CREATE NAVIGATION RIGHT
  #--------------------------------------------------
  $links = "";
  $url[0] = array("URL" => "", "URL-TEXT" => "", "ONCLICK" => "", "TARGET" => "_self");
  for ($i=0; $i<count($url); $i++) {
     $links .= "
        <tr height=\"15\">
			<td valign=\"top\"><img src=\"../standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
			<td valign=\"top\"><a href=\"".$url[$i]['URL']."\" class=\"sitenav\" target=\"".$url[$i]['TARGET']."\" onClick=\"".$url[$i]['ONCLICK']."\">".$url[$i]['URL-TEXT']."</a></td>
			<td valign=\"top\"><img src=\"../standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
		</tr>
		<tr height=\"15\">
            <td colspan=\"3\"><img src=\"../standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
		</tr>
       ";
  }
  include_once("../member/standard/navi.php5");
  $t->set_var(array("LINKS" => $links, "BANNER" => $banner, "JSNAVI" => $js_navi));
  $right_nav = $t->parse("","navi", true);
  #--------------------------------------------------


  #--------------------------------------------------
  # CREATE CONTENT "NEWS"
  #--------------------------------------------------
  if ($usr_priv > 0) {

      global $limit;
      $content = "";
      $step_width = 5;
      if (!isset($limit)) $limit = 0;

      $start_value = $limit*$step_width;
      $end_value = $limit+$step_width;
      $get_max = $svo->doSQL("select * from ".$table['News']." order by news_date desc;");
      $max = $svo->countRows($get_max);
      $sql = $svo->doSQL("select n.*, u.* from ".$table['News']." as n, ".$table['User']." as u where n.news_author=u.usr_id order by news_date desc limit ".$start_value.",".$end_value.";");

      if ($limit > 0) $BACKWARD = "<a href=\"news.php5?limit=".($limit-1)."\" class=\"news\" target=\"_self\">zur&uuml;ck</a>";
      else $BACKWARD = "&nbsp;";
      if ($max > (($limit+1)*$step_width)) $FORWARD = "<a href=\"news.php5?limit=".($limit+1)."\" class=\"news\" target=\"_self\">weiter</a>";
      else $FORWARD = "&nbsp;";

      while ($tupel = $svo->getRecordset($sql)) {
          $author = "<a href=\"mailto:".$tupel['usr_email']."\" class=\"news\">".$tupel['usr_vname']." ".$tupel['usr_name']."</a>";

          $t->set_var(array("HEADLINE"  => $tools->html_replace($tupel['news_headline']),
                            "DATUM"     => $time->out($tupel['news_date'],"d"),
                            "TEXT"      => $tools->html_replace($tupel['news_text']),
                            "AUTHOR"    => $author,
                            "ANCHOR"    => $tupel['news_id']));
          $content .= $t->parse("", "news", true);
      }
      $content .= "
      <div align=\"center\" class=\"text\"><br>
        <table width=\"80%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">
         	<tr>
						    <td width=\"33%\" align=\"center\" valign=\"top\" class=\"newsText\">".$BACKWARD."</td>
						    <td width=\"34%\" align=\"center\" valign=\"top\" class=\"newsText\"><a href=\"#top\" class=\"news\">top</a></td>
						    <td width=\"33%\" align=\"center\" valign=\"top\" class=\"newsText\">".$FORWARD."</td>
						</tr>
        </table>
        <br>
         insgesamt ".$max." Eintr&auml;ge
      </div>
      ";
  } else $content = "
  <script language=\"javascript\">
  <!--
  alert('Du besitzt leider nicht die erforderlichen Rechte,\\num diese Seite anzeigen zu lassen!');
  window.location.replace('index.php5');
  //-->
  </script>
  ";
  #--------------------------------------------------

  #--------------------------------------------------
  # PARSE & OUTPUT
  #--------------------------------------------------
  $t->set_var(array("sitenav" => "MEMBERAREA -> NEWS",
                    "content" => $content."<br>",
                    "navi" => $right_nav));

  $t->parse("ALL", "page", true);
  $t->p("ALL");
?>
